package cn.zwx.goods.svc.service.impl;

import cn.zwx.goods.svc.domain.entity.BrandEntity;
import cn.zwx.goods.svc.domain.entity.CategoryBrandEntity;
import cn.zwx.goods.svc.domain.entity.CategoryEntity;
import cn.zwx.goods.svc.mapper.CategoryBrandMapper;
import cn.zwx.goods.svc.service.CategoryBrandService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangwenxue
 */
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {

    @Resource
    private CategoryBrandMapper categoryBrandMapper;


    @Override
    public List<CategoryEntity> selectCategoryByBrandId(Integer brandId) {
        return categoryBrandMapper.selectCategoryByBrandId(brandId);
    }

    @Override
    public List<BrandEntity> selectListByCategoryId(Long categoryId) {
        return categoryBrandMapper.selectListByCategoryId(categoryId);
    }

    @Override
    public int insert(CategoryBrandEntity categoryBrandEntity) {
        return categoryBrandMapper.insertSelective(categoryBrandEntity);
    }

    @Override
    public int delete(Integer categoryId, Integer brandId) {
        LambdaQueryWrapper<CategoryBrandEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CategoryBrandEntity::getCategoryId,categoryId);
        queryWrapper.eq(CategoryBrandEntity::getBrandId,brandId);
        return categoryBrandMapper.delete(queryWrapper);
    }

    @Override
    public int delete(Integer brandId) {
        LambdaQueryWrapper<CategoryBrandEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CategoryBrandEntity::getBrandId,brandId);
        return categoryBrandMapper.delete(queryWrapper);
    }
}
